<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>使用 ref 实现双向数据绑定</title>
</head>

<body>
  <div id="vue-app">
    <h1>双向数据绑定 / input / select /textareav</h1>
    <label>姓名:</label>
    <input type="text" ref="refName" @input="changeName">
    <span>{{name}}</span>
    <br>
    <label>年龄:</label>
    <input type="text" ref="refAge" @input="changeAge">
    <span>{{age}}</span>
  </div>

  <!-- <script src="../../node_modules/vue/dist/vue.min.js"></script> -->
  <script src="https://cdn.bootcdn.net/ajax/libs/vue/2.6.12/vue.min.js"></script>
  <script>
    new Vue({
      el: "#vue-app",
      data: {
        name: "Henry",
        age: 18
      },
      methods: {
        changeName(ev) {
          console.log(this.$refs);
          this.name = this.$refs.refName.value;
        },
        changeAge(ev) {
          this.age = this.$refs.refAge.value;
        },
      }
    });
  </script>
</body>

</html>